﻿using System.Collections.Generic;
using System.Linq;
using Xunit.Should;

namespace Adjunct.Framework.Nuspec
{
	public static class NuspecAssertions
	{
		public static void ShouldEqual(this NuspecManifest actual, NuspecManifest expected)
		{
			actual.ShouldNotBeNull();
			expected.ShouldNotBeNull();
			actual.Metadata.ShouldEqual(expected.Metadata);
			actual.Includes.ShouldEqual(expected.Includes);
		}

		public static void ShouldEqual(this NuspecMetadata actual, NuspecMetadata expected)
		{
			actual.ShouldNotBeNull();
			expected.ShouldNotBeNull();
			actual.Authors.ShouldEqual(expected.Authors);
			actual.Copyright.ShouldEqual(expected.Copyright);
			actual.Dependencies.ShouldEqual(expected.Dependencies);
			actual.Description.ShouldEqual(expected.Description);
			actual.FrameworkReferences.ShouldEqual(expected.FrameworkReferences);
			actual.IconUrl.ShouldEqual(expected.IconUrl);
			actual.Id.ShouldEqual(expected.Id);
			actual.Language.ShouldEqual(expected.Language);
			actual.LibReferences.ShouldEqual(expected.LibReferences);
			actual.LicenseAcceptance.ShouldEqual(expected.LicenseAcceptance);
			actual.LicenseUrl.ShouldEqual(expected.LicenseUrl);
			actual.Owners.ShouldEqual(expected.Owners);
			actual.ProjectUrl.ShouldEqual(expected.ProjectUrl);
			actual.ReleaseNotes.ShouldEqual(expected.ReleaseNotes);
			actual.Summary.ShouldEqual(expected.Summary);
			actual.Tags.ShouldEqual(expected.Tags);
			actual.Title.ShouldEqual(expected.Title);
			actual.Version.ShouldEqual(expected.Version);
		}

		public static void ShouldEqual(this NuspecIncludes actual, NuspecIncludes expected)
		{
			actual.ShouldNotBeNull();
			expected.ShouldNotBeNull();
			actual.Count.ShouldEqual(expected.Count);
			List<NuspecInclude> actualItemsOrdered = actual.OrderBy(i => i.Source).ToList();
			List<NuspecInclude> expectedItemsOrdered = expected.OrderBy(i => i.Source).ToList();
			for (int i = 0; i < actual.Count; i++)
			{
				actualItemsOrdered[i].ShouldEqual(expectedItemsOrdered[i]);
			}
		}

		public static void ShouldEqual(this NuspecInclude actual, NuspecInclude expected)
		{
			actual.ShouldNotBeNull();
			expected.ShouldNotBeNull();
			actual.Source.ShouldEqual(expected.Source);
			actual.Target.ShouldEqual(expected.Target);
			actual.Exclude.ShouldEqual(expected.Exclude);
		}

		public static void ShouldEqual(this NuspecLibReferences actual, NuspecLibReferences expected)
		{
			actual.ShouldNotBeNull();
			expected.ShouldNotBeNull();
			actual.Count.ShouldEqual(expected.Count);
			List<NuspecLibReference> actualItemsOrdered = actual.OrderBy(i => i.Filename).ToList();
			List<NuspecLibReference> expectedItemsOrdered = expected.OrderBy(i => i.Filename).ToList();
			for (int i = 0; i < actual.Count; i++)
			{
				actualItemsOrdered[i].ShouldEqual(expectedItemsOrdered[i]);
			}
		}

		public static void ShouldEqual(this NuspecLibReference actual, NuspecLibReference expected)
		{
			actual.ShouldNotBeNull();
			expected.ShouldNotBeNull();
			actual.Filename.ShouldEqual(expected.Filename);
		}

		public static void ShouldEqual(this NuspecDependencies actual, NuspecDependencies expected)
		{
			actual.ShouldNotBeNull();
			expected.ShouldNotBeNull();
			actual.Count.ShouldEqual(expected.Count);
			List<NuspecDependency> actualItemsOrdered = actual.OrderBy(i => i.Id).ToList();
			List<NuspecDependency> expectedItemsOrdered = expected.OrderBy(i => i.Id).ToList();
			for (int i = 0; i < actual.Count; i++)
			{
				actualItemsOrdered[i].ShouldEqual(expectedItemsOrdered[i]);
			}
		}

		public static void ShouldEqual(this NuspecDependency actual, NuspecDependency expected)
		{
			actual.ShouldNotBeNull();
			expected.ShouldNotBeNull();
			actual.Id.ShouldEqual(expected.Id);
			actual.Version.ShouldEqual(expected.Version);
		}
	}
}